package com.it.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.it.entity.coverage.AiInsuranceCoverage;
import com.it.entity.preClaim.AiPreClaim;
import com.it.mapper.AiPreClaimMapper;
import com.it.service.AiPreClaimService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.R;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 预赔信息表（农户申请理想赔付及领导审核记录） 服务实现类
 * </p>
 *
 * @author lutao
 * @since 2025年09月24日
 */
@Service
public class AiPreClaimServiceImpl extends ServiceImpl<AiPreClaimMapper, AiPreClaim> implements AiPreClaimService {

    @Autowired
    private AiPreClaimMapper aiPreClaimMapper;




    @Override
    public R add(AiPreClaim aiPreClaim) {
        aiPreClaim.setFarmerApplyTime(LocalDateTime.now());
        aiPreClaim.setPreClaimStatus(1);

        return R.Success(aiPreClaimMapper.insert(aiPreClaim));
    }

    @Override
    public R updateByReportId(AiPreClaim aiPreClaim) {

        LambdaQueryWrapper<AiPreClaim> queryWrapper = new LambdaQueryWrapper<>();

        if(aiPreClaim.getReportId()!=null && !aiPreClaim.getReportId().isEmpty()){
            queryWrapper.eq(AiPreClaim::getReportId,aiPreClaim.getReportId());
        }
        aiPreClaim.setReviewTime(LocalDateTime.now());
        ;
        return R.Success("更新成功",aiPreClaimMapper.update(aiPreClaim,queryWrapper));
    }

    @Override
    public R aiPrelist(Integer pageNum, Integer pageSize, Integer reviewResult, Integer preClaimStatus, String reportId) {
        PageHelper.startPage(pageNum,pageSize);
        LambdaQueryWrapper<AiPreClaim> queryWrapper = new LambdaQueryWrapper<>();

        if(reviewResult != null){
            queryWrapper.eq(AiPreClaim::getReviewResult,reviewResult);
        }
        if(preClaimStatus != null){
            queryWrapper.eq(AiPreClaim::getPreClaimStatus,preClaimStatus);
        }
        if(reportId != null && !reportId.isEmpty()){
            queryWrapper.like(AiPreClaim::getReportId,reportId);
        }
        List<AiPreClaim> list = aiPreClaimMapper.selectList(queryWrapper);
        PageInfo<AiPreClaim> pageInfo = new PageInfo<>(list);

        return R.Success("查询成功",pageInfo);
    }
}
